package org.mysfit.ctp4j.core.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.modelmapper.ModelMapper;
import org.mysfit.ctp4j.core.service.BaseService;
import org.springframework.util.CollectionUtils;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 
 * @author long.gf
 *
 */
public abstract class AbstractBaseServiceImpl<M extends BaseMapper<T>, T, VO> 
	extends ServiceImpl<M, T> 
	implements BaseService<T, VO>
{
	protected abstract ModelMapper getModelMapper();
	protected abstract Class<VO> getVoCLass();
	
	@Override
	public List<VO> listAll() {
		List<T> entityList = super.list();
		if(CollectionUtils.isEmpty(entityList)) {
			return new ArrayList<>();
		}
		List<VO> voList = new ArrayList<>();
		entityList.stream().forEach(o -> {
			VO vo = getModelMapper().map(o, getVoCLass());
			voList.add(vo);
		});
		return voList;
	}
}
